<?php
namespace app\admin\controller;
use x\Xbase;
use x\my\TongLianCash;
class Task extends Xbase{

    #自动提现
    public function withdraw(){
        $ymt = date("Ymt");
        $rs = [];
        if (date('Ymd')!=$ymt) {
            $this->exit("1000");
        }

        $rs = $this->db->query("select id,money,bank_id from user where level>0 and is_auto=1 and money>0 and status=0 and auto_withdraw_day<? order by id asc limit 10",[$ymt]);
        if (!$rs)
            $this->exit("10");

        $sys = sys();
        foreach ($rs as $v) {
            e($v['id']);
            $rs = s("Withdraw", "c")->add($v['id'],$v['money'],'money',$v['bank_id'],$sys);
            if ($rs) {
                $this->db->update('user',['id'=>$v['id'],'auto_withdraw_day'=>$ymt]);
            }
        }
        $this->exit("1");
    }

    /**
     * 轮询处理充值
     * @return [type] [description]
     */
    public function dealRecharge(){
        $rs = $this->db->query("select * from recharge where pay_status=1 and is_count=0 order by id asc",[],1);
        if (!$rs) {
                $this->exit("1");
        }
        #购买产品
        if ($rs['tab']=='order_goods') {
            $order_nos = explode(',',$rs['tab_order_no']);
            foreach ($order_nos as $val) {
                //e($val);
                $result = s('OrderGoods','c')->pay($val);
            }
            $this->db->update('recharge',['id'=>$rs['id'],'is_count'=>1]);
        }
        #成为vip
        if ($rs['tab']=='user_vip') {
            //e($rs['tab_order_no']);
            s("UserVip", "c")->pay($rs["tab_order_no"]);
            $this->db->update('recharge',['id'=>$rs['id'],'is_count'=>1]);
        }
        #升级代理
        if ($rs['tab']=='user_upgrade') {
            //e($rs['tab_order_no']);
            s("UserUpgrade", "c")->pay($rs["tab_order_no"]);
            $this->db->update('recharge',['id'=>$rs['id'],'is_count'=>1]);
        }

        $this->exit("1");
    }

    //
    public function exit($s=1){
        exit($s);
        //js_url('',$s);
    }

}
